<html><head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"><title>Spline.pb</title></head>
<body bgcolor="#EFF1F0" link="#3A3966" vlink="#000000" alink="#000000">
<pre><font face="Courier New, Courier, mono"size="2"><font color="#3A3966">;
</font><font color="#3A3966">; ------------------------------------------------------------
</font><font color="#3A3966">;
</font><font color="#3A3966">;   PureBasic - Spline
</font><font color="#3A3966">;
</font><font color="#3A3966">;    (c) Fantaisie Software
</font><font color="#3A3966">;
</font><font color="#3A3966">; ------------------------------------------------------------
</font><font color="#3A3966">;
</font><font color="#3A3966">;An example of using SimpleSpline To make an Entity smoothly 
</font><font color="#3A3966">;follow a predefined path With spline interpolation.

</font><b><font color="#3A3966">IncludeFile</font></b> <font color="#924B72">#PB_Compiler_Home</font> + "examples/3d/Screen3DRequester.pb"

<b><font color="#3A3966">Define</font></b>.f Time, TimeN, pas = 1, x, y, z, TimeSinceLastFrame

<b><font color="#3A3966">If</font></b> <font color="#3A3966">InitEngine3D</font>()
  
<font color="#3A3966">  InitSprite</font>()
<font color="#3A3966">  InitKeyboard</font>()
<font color="#3A3966">  InitMouse</font>()
  
  <b><font color="#3A3966">If</font></b> <font color="#3A3966">Screen3DRequester</font>()
<font color="#3A3966">    Add3DArchive</font>(<font color="#924B72">#PB_Compiler_Home</font> + "examples/3d/Data/"                , <font color="#924B72">#PB_3DArchive_FileSystem</font>)    
<font color="#3A3966">    Add3DArchive</font>(<font color="#924B72">#PB_Compiler_Home</font> + "examples/3d/Data/Textures"        , <font color="#924B72">#PB_3DArchive_FileSystem</font>)
<font color="#3A3966">    Add3DArchive</font>(<font color="#924B72">#PB_Compiler_Home</font> + "examples/3d/Data/Models"          , <font color="#924B72">#PB_3DArchive_FileSystem</font>)
<font color="#3A3966">    Add3DArchive</font>(<font color="#924B72">#PB_Compiler_Home</font> + "examples/3d/Data/Scripts"         , <font color="#924B72">#PB_3DArchive_FileSystem</font>)
<font color="#3A3966">    Add3DArchive</font>(<font color="#924B72">#PB_Compiler_Home</font> + "examples/3d/Data/Packs/skybox.zip", <font color="#924B72">#PB_3DArchive_Zip</font>)
<font color="#3A3966">    Parse3DScripts</font>()
    
<font color="#3A3966">    WorldShadows</font>(<font color="#924B72">#PB_Shadow_Modulative</font>, 0,<font color="#3A3966"> RGB</font>(175, 175, 175))
    

    <font color="#3A3966">;- Ground
</font><font color="#3A3966">    CreateMaterial</font>(0,<font color="#3A3966"> LoadTexture</font>(0, "Dirt.jpg"))
<font color="#3A3966">    CreatePlane</font>(0, 1200, 1200, 1, 1, 5, 5)
<font color="#3A3966">    CreateEntity</font>(0,<font color="#3A3966"> MeshID</font>(0),<font color="#3A3966"> MaterialID</font>(0), 500, 0, -500)
    
    <font color="#3A3966">;- Cylinder - check point
</font><font color="#3A3966">    CreateCylinder</font>(3, 10, 100)
<font color="#3A3966">    CreateEntity</font>(4,<font color="#3A3966"> MeshID</font>(3), <font color="#924B72">#PB_Material_None</font>, 50,  0,   50)
<font color="#3A3966">    CreateEntity</font>(5,<font color="#3A3966"> MeshID</font>(3), <font color="#924B72">#PB_Material_None</font>, 50,  0, -950)
<font color="#3A3966">    CreateEntity</font>(6,<font color="#3A3966"> MeshID</font>(3), <font color="#924B72">#PB_Material_None</font>, 950, 0, -950)
<font color="#3A3966">    CreateEntity</font>(7,<font color="#3A3966"> MeshID</font>(3), <font color="#924B72">#PB_Material_None</font>, 950, 0,   50)
<font color="#3A3966">    CreateEntity</font>(8,<font color="#3A3966"> MeshID</font>(3), <font color="#924B72">#PB_Material_None</font>, 450, 0, -450)
    
    <font color="#3A3966">;- Robot
</font>    <font color="#3A3966">;
</font><font color="#3A3966">    LoadMesh</font>(1, "robot.mesh")
<font color="#3A3966">    CreateEntity</font>(1,<font color="#3A3966"> MeshID</font>(1), <font color="#924B72">#PB_Material_None</font>, 0, 0, 0)
<font color="#3A3966">    ScaleEntity</font>(1, 3, 3, 3)
<font color="#3A3966">    StartEntityAnimation</font>(1, "Walk")
    
    <font color="#3A3966">;- Ninja
</font>    <font color="#3A3966">;
</font><font color="#3A3966">    LoadMesh</font>(2, "ninja.mesh")
<font color="#3A3966">    CreateEntity</font>(2,<font color="#3A3966"> MeshID</font>(2), <font color="#924B72">#PB_Material_None</font>, 500, 0, 400)
<font color="#3A3966">    ScaleEntity</font>(2, 1.4, 1.4, 1.4)  
<font color="#3A3966">    StartEntityAnimation</font>(2, "Walk", <font color="#924B72">#PB_EntityAnimation_Manual</font>)
    
    <font color="#3A3966">;- Camera
</font>    <font color="#3A3966">;
</font><font color="#3A3966">    CreateCamera</font>(0, 0, 0, 100, 100)
<font color="#3A3966">    MoveCamera</font>(0, 500, 1500, 1450, <font color="#924B72">#PB_Absolute</font>)
<font color="#3A3966">    CameraFOV</font>(0, 28)
<font color="#3A3966">    CameraBackColor</font>(0,$846748)
<font color="#3A3966">    CameraLookAt</font>(0, 500, 0, -500)
    
    <font color="#3A3966">;- Light
</font>    <font color="#3A3966">;
</font><font color="#3A3966">    AmbientColor</font>(<font color="#3A3966">RGB</font>(25, 25, 25))
<font color="#3A3966">    CreateLight</font>(0,<font color="#3A3966"> RGB</font>(200, 200, 200), -750, 750, -750)
    
    <font color="#3A3966">;- Spline Robot
</font>    <font color="#3A3966">;
</font>    spline =<font color="#3A3966"> CreateSpline</font>(<font color="#924B72">#PB_Any</font>)
<font color="#3A3966">    AddSplinePoint</font>(spline,<font color="#3A3966"> EntityX</font>(4), 0,<font color="#3A3966"> EntityZ</font>(4))
<font color="#3A3966">    AddSplinePoint</font>(spline,<font color="#3A3966"> EntityX</font>(8), 0,<font color="#3A3966"> EntityZ</font>(8))
<font color="#3A3966">    AddSplinePoint</font>(spline,<font color="#3A3966"> EntityX</font>(5), 0,<font color="#3A3966"> EntityZ</font>(5))
<font color="#3A3966">    AddSplinePoint</font>(spline,<font color="#3A3966"> EntityX</font>(6), 0,<font color="#3A3966"> EntityZ</font>(6))
<font color="#3A3966">    AddSplinePoint</font>(spline,<font color="#3A3966"> EntityX</font>(8), 0,<font color="#3A3966"> EntityZ</font>(8))
<font color="#3A3966">    AddSplinePoint</font>(spline,<font color="#3A3966"> EntityX</font>(7), 0,<font color="#3A3966"> EntityZ</font>(7)) 
<font color="#3A3966">    AddSplinePoint</font>(spline,<font color="#3A3966"> EntityX</font>(4), 0,<font color="#3A3966"> EntityZ</font>(4))
    
    <font color="#3A3966">;- Spline Ninja
</font>    <font color="#3A3966">;
</font>    splineN =<font color="#3A3966"> CreateSpline</font>(<font color="#924B72">#PB_Any</font>)
<font color="#3A3966">    AddSplinePoint</font>(splineN,<font color="#3A3966"> EntityX</font>(2),<font color="#3A3966"> EntityY</font>(2),<font color="#3A3966"> EntityZ</font>(2))
<font color="#3A3966">    AddSplinePoint</font>(splineN,<font color="#3A3966"> EntityX</font>(1),<font color="#3A3966"> EntityY</font>(1),<font color="#3A3966"> EntityZ</font>(1))
    
    <b><font color="#3A3966">Repeat</font></b>
<font color="#3A3966">      Screen3DEvents</font>()
      
<font color="#3A3966">      ExamineKeyboard</font>()
      
      <font color="#3A3966">; Robot
</font><font color="#3A3966">      ComputeSpline</font>(spline, time) <font color="#3A3966">; Should be called before using SplineX(); SplineY() and SplineZ()
</font>      x =<font color="#3A3966"> SplineX</font>(spline)
      y =<font color="#3A3966"> SplineY</font>(spline)
      z =<font color="#3A3966"> SplineZ</font>(spline)
      
<font color="#3A3966">      EntityLookAt</font>(1, x,<font color="#3A3966"> EntityY</font>(1), z, 1, 0, 0)
<font color="#3A3966">      MoveEntity</font>(1, x, y, z, <font color="#924B72">#PB_Absolute</font>)
      
      time + pas * TimeSinceLastFrame / 35
      
      <b><font color="#3A3966">If</font></b> time &gt; 1
        Time = 0
      <b><font color="#3A3966">EndIf</font></b>
      
      <font color="#3A3966">; Ninja
</font><font color="#3A3966">      ComputeSpline</font>(splineN, TimeSinceLastFrame/2) <font color="#3A3966">; Should be called before using SplineX(); SplineY() and SplineZ()
</font>      x =<font color="#3A3966"> SplineX</font>(splineN)
      y =<font color="#3A3966"> SplineY</font>(splineN)
      z =<font color="#3A3966"> SplineZ</font>(splineN)
      
<font color="#3A3966">      EntityLookAt</font>(2, x,<font color="#3A3966"> EntityY</font>(2), z)
<font color="#3A3966">      MoveEntity</font>(2, x, y, z, <font color="#924B72">#PB_Absolute</font>)
<font color="#3A3966">      AddEntityAnimationTime</font>(2, "Walk", TimeSinceLastFrame*1000 / 2)
      
<font color="#3A3966">      UpdateSplinePoint</font>(splineN, 0,<font color="#3A3966"> EntityX</font>(2),<font color="#3A3966"> EntityY</font>(2),<font color="#3A3966"> EntityZ</font>(2))
<font color="#3A3966">      UpdateSplinePoint</font>(splineN, 1,<font color="#3A3966"> EntityX</font>(1),<font color="#3A3966"> EntityY</font>(1),<font color="#3A3966"> EntityZ</font>(1))
      
      TimeSinceLastFrame =<font color="#3A3966"> RenderWorld</font>() / 1000
      
<font color="#3A3966">      FlipBuffers</font>()
    <b><font color="#3A3966">Until</font></b> <font color="#3A3966">KeyboardPushed</font>(<font color="#924B72">#PB_Key_Escape</font>)
    
    <b><font color="#3A3966">End</font></b>
    
  <b><font color="#3A3966">EndIf</font></b> 
<b><font color="#3A3966">Else</font></b>
<font color="#3A3966">  MessageRequester</font>("Error","Can't initialize engine3D")
<b><font color="#3A3966">EndIf</font></b> 
</font></pre>
</body></html>
